# 把当前项目根目录加入Python环境路径
import sys
sys.path.append('/www/wwwroot/panda-ai')

from common.api_tools import generate_key
from models import user_keys
from models.user_keys import UserKey
from models.base import get_db
from common.constants import KEYUSED_MAXTIMES

def create_key():
    str_key = generate_key()
    db = next(get_db())
    user_key = UserKey().create(db, str_key, KEYUSED_MAXTIMES)
    if not user_key:
        print("创建密钥失败")
    print(f"生成的密钥为：{str_key}")

if __name__ == "__main__":
    create_key()